const User = require('../model/use.model')

class UserService{

    // 创建用户
    async CreateUser(user_name,password){

        // await表达式:promise对象的值
        const res = await User.create({user_name,password})
        console.log(res.dataValues);

        return res;
    }

    // 用户信息
    async getUserInfo({id,user_name,password,isadmin}){
        const whereOpt={};

        id && Object.assign(whereOpt,{id})
        user_name && Object.assign(whereOpt,{user_name})
        password && Object.assign(whereOpt,{password})
        isadmin && Object.assign(whereOpt,{isadmin})

        const res = await User.findOne({
            attributes:['id','user_name','password','isadmin'],
            where:whereOpt
        })

        return res ? res.dataValues : null;
    }

}

module.exports = new UserService();